package cn.com.spic.demo.impl;

import cn.com.spic.demo.api.EmployeeService;
import cn.com.spic.demo.dao.EmployeeDAO;
import cn.com.spic.demo.dto.EmployeeDTO;
import cn.com.spic.demo.po.EmployeePO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeDAO employeeDAO;

    public EmployeeDTO getEmployeeById(String userCode) {
        EmployeePO po = employeeDAO.getEmployeeById(userCode);
        EmployeeDTO dto = new EmployeeDTO();
        if (po != null) {
            BeanUtils.copyProperties(po, dto);
        }
        return dto;
    }

    @Override
    public Integer updEmpByCode(EmployeeDTO employeeDTO) {
        EmployeePO po = new EmployeePO();
        BeanUtils.copyProperties(employeeDTO, po);
        return employeeDAO.updEmpByCode(po);
    }

    @Override
    public Integer saveEmp(Map<String, String> map) {
        return employeeDAO.saveEmp(map);
    }

}
